package com.training.web.controller.comtent;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.training.common.annotation.Log;
import com.training.common.core.controller.BaseController;
import com.training.common.core.domain.AjaxResult;
import com.training.common.enums.BusinessType;
import com.training.content.domain.SysZhAddress;
import com.training.content.service.ISysZhAddressService;
import com.training.common.utils.poi.ExcelUtil;
import com.training.common.core.page.TableDataInfo;

/**
 * 区域Controller
 * 
 * @author training
 * @date 2021-10-25
 */
@RestController
@RequestMapping("/zh/address")
public class SysZhAddressController extends BaseController
{
    @Autowired
    private ISysZhAddressService sysZhAddressService;

    /**
     * 查询区域列表
     */
    @PreAuthorize("@ss.hasPermi('zh:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysZhAddress sysZhAddress)
    {
        startPage();
        List<SysZhAddress> list = sysZhAddressService.selectSysZhAddressList(sysZhAddress);
        return getDataTable(list);
    }

    /**
     * 导出区域列表
     */
    @PreAuthorize("@ss.hasPermi('zh:address:export')")
    @Log(title = "区域", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysZhAddress sysZhAddress)
    {
        List<SysZhAddress> list = sysZhAddressService.selectSysZhAddressList(sysZhAddress);
        ExcelUtil<SysZhAddress> util = new ExcelUtil<SysZhAddress>(SysZhAddress.class);
        return util.exportExcel(list, "区域数据");
    }

    /**
     * 获取区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('zh:address:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return AjaxResult.success(sysZhAddressService.selectSysZhAddressByAreaId(areaId));
    }

    /**
     * 新增区域
     */
    @PreAuthorize("@ss.hasPermi('zh:address:add')")
    @Log(title = "区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysZhAddress sysZhAddress)
    {
        return toAjax(sysZhAddressService.insertSysZhAddress(sysZhAddress));
    }

    /**
     * 修改区域
     */
    @PreAuthorize("@ss.hasPermi('zh:address:edit')")
    @Log(title = "区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysZhAddress sysZhAddress)
    {
        return toAjax(sysZhAddressService.updateSysZhAddress(sysZhAddress));
    }

    /**
     * 删除区域
     */
    @PreAuthorize("@ss.hasPermi('zh:address:remove')")
    @Log(title = "区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Long[] areaIds)
    {
        return toAjax(sysZhAddressService.deleteSysZhAddressByAreaIds(areaIds));
    }
}
